package club.emergency.wechat.common.response;

import club.emergency.wechat.common.utils.JsonConvert;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.common.response
 * Date: 2018/11/5
 *
 * @author: 快乐的小菌菌
 * Description: 服务提供者统一响应实体封装，为了规范返回结果格式,provider统一返回String类型
 * errCode {@link StatusCode}中查询，没有的可以自己编辑新增
 */
@Data
@NoArgsConstructor
public class ResponseEntity {
    private int statusCode;
    private String statusMsg;
    private Object data;

    public ResponseEntity(int statusCode, String statusMsg, Object data) {
        this.statusCode = statusCode;
        this.statusMsg = statusMsg;
        this.data = data;
    }

    public ResponseEntity(int statusCode, String statusMsg) {
        this.statusCode = statusCode;
        this.statusMsg = statusMsg;
    }

    /**
     * 相应处理成功返回字符串
     *
     * @param statusCode 状态码
     * @param statusMsg  状态信息
     * @param data       需要封装的数据
     * @return json字符串
     */
    public static String ok(int statusCode, String statusMsg, Object data) {
        return new JsonConvert<ResponseEntity>().jsonEncode(new ResponseEntity(statusCode, statusMsg, data));
    }

    /**
     * 相应处理成功返回字符串
     *
     * @param statusCode 状态码
     * @param statusMsg  状态信息
     * @return json字符串
     */
    public static String ok(int statusCode, String statusMsg) {
        return new JsonConvert<ResponseEntity>().jsonEncode(new ResponseEntity(statusCode, statusMsg, null));
    }

    /**
     * 处理失败返回字符串
     *
     * @param statusCode 状态码
     * @param statusMsg  状态信息
     * @param data       需要封装的数据
     * @return json字符串
     */
    public static String error(int statusCode, String statusMsg, Object data) {
        return new JsonConvert<ResponseEntity>().jsonEncode(new ResponseEntity(statusCode, statusMsg, data));
    }

    /**
     * 处理失败返回字符串
     *
     * @param statusCode 状态码
     * @param statusMsg  状态信息
     * @return json字符串
     */
    public static String error(int statusCode, String statusMsg) {
        return new JsonConvert<ResponseEntity>().jsonEncode(new ResponseEntity(statusCode, statusMsg, null));
    }

}
